package gamagora.box2d
{
	import Box2D.Collision.Shapes.b2PolygonShape;
	import Box2D.Dynamics.b2Body;
	
	import org.flixel.FlxGroup;
	
	public class OSPhysicBox extends OSPhysicSprite
	{
		public function OSPhysicBox(x:Number=0, y:Number=0, w:Number = 0, h:Number = 0, physicWidth:Number = 0, physicHeight:Number = 0, simpleGraphic:Class=null)
		{
			super(x, y, simpleGraphic);
			_nbSprites = 1;
			width = w;
			height = h;
			_physicWidth = physicWidth == 0 ? width : physicWidth;
			_physicHeight = physicHeight == 0 ? height : physicHeight;
		}
		
		public override function create(group:FlxGroup):void
		{
			super.create(group);
			var boxShape:b2PolygonShape = new b2PolygonShape();
			boxShape.SetAsBox((_physicWidth / 2) / OSPhysicWorld.ratio, (_physicHeight / 2) / OSPhysicWorld.ratio);
			_physic.fixDef.shape = boxShape;
			_physic.create(x + (_physicWidth / 2), y + (_physicHeight / 2));
			_physic.fixture.SetUserData(_data);
		}
		
		public override function update():void
		{
			x = _physic.getX() - _physicWidth / 2;
			y = _physic.getY() - _physicHeight / 2;
			angle = _physic.getAngle();
		}
		
	}
}